#ifndef __H_HOST_BASE_H__
#define __H_HOST_BASE_H__

#include "Packet.h"
#include "spiderExtern.h"
#include "NodeDefine.h"
#include "CClient.h"
#include "ClientHandler.h"
#include <google/protobuf/message.h>

enum 
{
	HOST_EV_CLIENT_CLOSE = 0x100,
	HOST_EV_BACK_CLOSE = 0x101,
	HOST_EV_BACK_CONNECTED = 0x102,
	HOST_EV_CACHE_CONN_SUCCESS = 0x103,
	HOST_EV_NEW_CONN_CHECK = 0x104,
	HOST_EV_CLIENT_REGISTER = 0x105,
	HOST_EV_GAME_INIT = 0x106,
	HOST_EV_PUBULISH_SERVICE = 0x107,
	HOST_EV_CLIENT_OFFLINE = 0x108
};

typedef struct spiderEvent
{
	int  evID;
	union {
		void*  ptr;
		int    iParam;
		int64  i64Param;
	} evParam;
}SpiderEvent;

class CNodeServer;
class  CHostBase
{
public:
	CHostBase(){};
	virtual ~CHostBase(){};

	virtual void Init() = 0;
	virtual int ProcEvent(int ev_id, SpiderEvent* pEvent = NULL) = 0;
	virtual int ProcPacket(NETInputPacket* inputPkg, SocketHandler* pSocketHandler) = 0;
	virtual int OnEventCallBack(stEventItem* pitem);

	virtual int SendPacketToService(CCPacketBase* pPkg, int dst_type, int mod_param = 0);

	// note:: packet size must less then 10KB
	virtual int PushMessage(CCPacketBase* pPkg, int dst_type, int dst_svid);
	virtual int BroadcastMessage(CCPacketBase* pPkg, int dst_type);
	virtual int PushCmd(CCPacketBase* pPkg, int cmd);

	int BroadcastMessageDirect(CCPacketBase* pPkg, const unsigned short dst_type);
	int BroadcastMessageDirect(unsigned int cmd, const ::google::protobuf::Message* pb, unsigned short srctype, unsigned int srcid, unsigned short dsttype, bool encryp = false);
	int BroadcastMessageDirect(unsigned int cmd, const ::google::protobuf::Message* pb, unsigned short dsttype, bool encryp = false);

	//response server request
	int SendPb(SocketHandler* handler, unsigned int cmd, unsigned short dsttype, unsigned int dstid, unsigned short srctype, unsigned int srcid, const ::google::protobuf::Message* pb, bool encryp = false);
	int SendPb(SocketHandler* handler, unsigned int cmd, unsigned short dsttype, unsigned int dstid, const ::google::protobuf::Message* pb, bool encryp = false);
	int SendPb(SocketHandler* handler, unsigned int cmd, const ::google::protobuf::Message* pb, bool encryp = false);
	int SendPlayerPb(SocketHandler* handler, unsigned int cmd, unsigned int uid, const ::google::protobuf::Message* pb, bool encryp = true);

	//push to player client
	int PushPlayerMsg(unsigned int uid, unsigned int cmd, const ::google::protobuf::Message* pb, bool encryp = true);

	//send to player via agent
	int SendToPlayerViaAgent(const unsigned int cmd, const ::google::protobuf::Message* pb, const unsigned int uid, const unsigned int agentid, bool encryp = true);

	//send msg to one server by mod or rand
	int SendtoSrv(CCPacketBase* pPkg, unsigned short dsttype, unsigned int mod_uid = 0);
	int SendtoSrv(unsigned int cmd, unsigned short dsttype, const ::google::protobuf::Message* pb, unsigned int mod_uid , unsigned short srctype , unsigned int srcid, bool encryp = false, unsigned int seq = 0);
	int SendtoSrv(unsigned int cmd, unsigned short dsttype, const ::google::protobuf::Message* pb, unsigned int mod_uid, bool encryp = false, unsigned int seq = 0);

	//send msg to one appointed
	virtual int SendPacket(CCPacketBase* pPkg, int dst_type, int dst_svid = 0);
	int SendtoOneSrv(unsigned int cmd, const ::google::protobuf::Message* pb, unsigned short dsttype, unsigned int dstid, unsigned short srctype, unsigned int srcid, bool encryp = false, unsigned int seq = 0);
	int SendtoOneSrv(unsigned int cmd, const ::google::protobuf::Message* pb, unsigned short dsttype, unsigned int dstid, bool encryp = false, unsigned int seq = 0);

	//Mult Thread
	int InitMtSend(void);
	//send msg to one mod server
	int MtSendtoSrv(unsigned int cmd, unsigned short dsttype, const ::google::protobuf::Message* pb, unsigned int mod_uid, unsigned short srctype, unsigned int srcid, bool encryp = false, unsigned int seq = 0);
	int MtSendtoSrv(unsigned int cmd, unsigned short dsttype, const ::google::protobuf::Message* pb, unsigned int mod_uid, bool encryp = false, unsigned int seq = 0);
	int MtSendtoSrv(unsigned int cmd, unsigned short dsttype, std::string&& data, unsigned int mod_uid, unsigned short srctype, unsigned int srcid, bool encryp = false, unsigned int seq = 0);
	int MtSendtoSrv(unsigned int cmd, unsigned short dsttype, std::string&& data, unsigned int mod_uid, bool encryp = false, unsigned int seq = 0);

	//send msg to one appointed
	int MtSendtoOneSrv(unsigned int cmd, const ::google::protobuf::Message* pb, unsigned short dsttype, unsigned int dstid, unsigned short srctype, unsigned int srcid, bool encryp = false, unsigned int seq = 0);
	int MtSendtoOneSrv(unsigned int cmd, const ::google::protobuf::Message* pb, unsigned short dsttype, unsigned int dstid, bool encryp = false, unsigned int seq = 0);
	int MtSendtoOneSrv(unsigned int cmd, std::string&& data, unsigned short dsttype, unsigned int dstid, unsigned short srctype, unsigned int srcid, bool encryp = false, unsigned int seq = 0);
	int MtSendtoOneSrv(unsigned int cmd, std::string&& data, unsigned short dsttype, unsigned int dstid, bool encryp = false, unsigned int seq = 0);

	//send to player via agent
	int MtSendToPlayerViaAgent(const unsigned int cmd, const ::google::protobuf::Message* pb, const unsigned int uid, const unsigned int agentid, bool encryp = true, unsigned int seq = 0);

	int MtPushPlayerMsg(unsigned int uid, unsigned int cmd, const ::google::protobuf::Message* pb, bool encryp = true, unsigned int seq = 0);

	int MtBroadcastMessageDirect(unsigned int cmd, const ::google::protobuf::Message* pb, unsigned short srctype, unsigned int srcid, unsigned short dsttype, bool encryp = false, unsigned int seq = 0);
	int MtBroadcastMessageDirect(unsigned int cmd, const ::google::protobuf::Message* pb, unsigned short dsttype, bool encryp = false, unsigned int seq = 0);
	int MtBroadcastMessageDirect(unsigned int cmd, std::string&& data, unsigned short srctype, unsigned int srcid, unsigned short dsttype, bool encryp = false, unsigned int seq = 0);
	int MtBroadcastMessageDirect(unsigned int cmd, std::string&& data, unsigned short dsttype, bool encryp = false, unsigned int seq = 0);


public:
	CNodeServer* m_pNode;  
};



#endif